<?php
Yii::app()->clientScript->registerScript('search', "
$('#search-button').toggle(function(){
        $('.search-form').toggle('slow');
        $(this).html('Masquer le formulaire de recherche');
        return false;
}, function(){
        $('.search-form').toggle('slow');
        $(this).html('Afficher le formulaire de recherche');
        return false;
});
$('#init-button').click(function(){
        $(':input','.search-form form')
                .not(':button, :submit, :reset, :hidden')
                .val('')
                .removeAttr('checked')
                .removeAttr('selected');
        $('select option:selected').removeAttr('selected');
        $('#grain-grid').yiiGridView('update', {
                data: '',
                url: '" . Yii::app()->createUrl('grain/admin') . "'
        });
        return false;
});
$('.search-form form').submit(function(){
        $('#grain-grid').yiiGridView('update', {
                data: $(this).serialize()
        });
        return false;
});
");
$this->pageTitle = "Selavenir - Liste des grains";
?>


<div class="container">
        
        <?php if(Yii::app()->user->hasFlash('grain')) {?>
        <div class="row">
                <div class="span12">
                        <div class="alert alert-success alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                <?php echo Yii::app()->user->getFlash('grain'); ?>
                                <?php
                                Yii::app()->clientScript->registerScript('close-alert', "
                                        window.setTimeout(function() { $('.alert').alert('close'); }, 4000);
                                ");
                                ?>
                        </div>
                </div>
        </div>
        <?php } ?>
        
        <div class="row">
                <div class="span12">                    
                        <h1>Liste des grains</h1>
                </div>
        </div>
        <div class="row">
                <div class="span12">                    
                        <?php echo CHtml::link('Afficher le formulaire de recherche','#',array("class"=>"btn btn-mini btn-info","id"=>"search-button"));?>                                      
                </div>
        </div>
        <div class="row">
                <div class="span12">
                        <div class="search-form" style="display:none">
                        <?php $this->renderPartial('_search',array(
                                'model'=>$model
                        )); ?>
                        </div><!-- search-form -->

                        <?php $this->widget('ext.bs3gridview.widgets.Bs3GridView', array(
                                'id'=>'grain-grid',
                                'dataProvider'=>$model->search(),
                                'columns'=>array(
										'id',
                                        'nom',
                                        'descr',
                                        array(
                                                'name'=>'sdomaine',
                                                'value'=>'$data->iddomaine0->lib',
                                        ),
                                        array(
                                                'name'=>'stype',
                                                'value'=>'$data->idtype0->lib',
                                        ),
										array(
												'name'=>'sstatus',
												'value'=>'$data->status == 1 ? "Validé" : "Non validé"',
												'visible'=>Yii::app()->user->admin == 1
										),
                                        array(
                                                'class'=>'CButtonColumn',
                                                'template' => '{view} {update} {delete}',
												'viewButtonImageUrl' => false,
                                                'updateButtonImageUrl' => false, 
                                                'deleteButtonImageUrl' => false, 
                                                'buttons'=>array(
																		'view'=>array(
																				'label'=>"",
																				'options'=>array(
																						"class"=>"glyphicon glyphicon-search",
																						"title"=>"Voir"
																				),
																		),
                                                                        'update'=>array(
                                                                                        'label'=>"",
                                                                                        'options'=>array(
                                                                                                "class"=>"glyphicon glyphicon-edit",
                                                                                                "title"=>"Mettre à jour"
                                                                                                ),
                                                                                ),
                                                                        'delete'=>array(
                                                                                        'label'=>"",
                                                                                        'options'=>array(
                                                                                                "class"=>"glyphicon glyphicon-remove",
                                                                                                "title"=>"Supprimer"
                                                                                                ),
                                                                                ),  
                                                                        ),  
                                        ),
                                ),
                        )); ?>
                </div>
        </div>
</div>